package dtm

import (
	"context"
	"gitee.com/xuyiping_admin/pkg/di"
	"go.uber.org/dig"
	"kpt-dtm/config"
	"kpt-dtm/model"
	"kpt-dtm/model/dtm"
	"kpt-dtm/model/yyn"
	"kpt-dtm/service/Mqtt"
	"kpt-dtm/service/http"
	"kpt-dtm/service/kptstore"
)

var Module = di.Options(di.Provide(NewStore))

type Hub struct {
	dig.In
	OpsService Service
}

type StoreEntry struct {
	dig.In
	DB          *kptstore.DB
	Cfg         *config.AppConfig
	HttpClient  *http.ClientService
	MqttManager *Mqtt.MqttManager
}

func NewStore(store StoreEntry) Service {
	return &store
}

func NewStoreEntry(cfg *config.AppConfig) *StoreEntry {
	return &StoreEntry{
		Cfg:        cfg,
		HttpClient: nil,
	}
}

//go:generate mockgen -destination mock/dtmservice.go -package dtmservicemock kpt-dtm/module/backend DtmService
type Service interface {
	Common(ctx context.Context, pastureId int64, dtm, path string) (interface{}, error)
	OldAuth(ctx context.Context, id int64) (interface{}, error)
	OldTest(ctx context.Context, id int64, name string) error
	DtmService
	YYNService
	CrontabService
}

type DtmService interface {
	DtmCommon(ctx context.Context, pastureId int64, path string) (interface{}, error)
	// Login 登录
	Login(ctx context.Context, pastureId int64) (*dtm.LoginResponse, error)
}

type YYNService interface {
	YynCommon(ctx context.Context, pastureId int64, path string) (interface{}, error)
	Token(ctx context.Context, yConfig *model.YConfig) (*yyn.TokenResponse, error)
	SynCowHouseInfo(ctx context.Context, yConfig *model.YConfig) (*yyn.CowsHouseResponse, error)
}

type CrontabService interface {
	// DataHandle 定时任务
	DataHandle() error
}
